<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>setInterval实现电子时钟</h1>
<hr>

<input type="text" id="myclock" value="" readonly/>
<input type="button" value="停止" onclick="stopclock();"/>
<input type="button" value="开始" onclick="startclock();"/>

<script>
    let mytimer;
    function show(){
        let d = new Date();
        let myclock = d.toLocaleString();
        document.getElementById("myclock").value=myclock;
    }

    function stopclock(){
        //停止一个定时器对象。
        clearInterval(mytimer);
    }

    function startclock(){
        mytimer = setInterval("show()",1000);
    }

    function myclock(){
        show();
        mytimer = setInterval("show()",1000);
    }
    window.onload = myclock;
</script>
</body>
</html>